﻿#include "DXUT.h"
#include "RenderAssistLineShell.h"


CRenderAssistLineShell::CRenderAssistLineShell(void):RenderTech()	
{
	m_pAssistLineVB = NULL;
	m_pAssistLineVBLayout = NULL;
	m_iNumAssistVertices = 0;

	m_pRenderTech = NULL;
	m_pWorldViewProjMat = NULL;
}


CRenderAssistLineShell::~CRenderAssistLineShell(void)
{
	OnD3D11DestroyDevice(NULL);
}

void CRenderAssistLineShell::CreateEmphasizeLine(int iSegment, float thetaMin, float thetaMax, float phiMin, float phiMax, float radius1, float radius2,
	CGrowableArray<PT_VertColor>& ptsArray, D3DXVECTOR4 fColor)
{
	float fThetaStep = (thetaMax-thetaMin)/iSegment;
	float fPhiStep = (phiMax - phiMin)/iSegment;

	float fCurTheta = thetaMin;
	float fCurPhi = phiMax;
	float cosPhi = cos(fCurPhi);
	float sinPhi = sin(fCurPhi);

	D3DXVECTOR3 oldPt = D3DXVECTOR3(radius1*cosPhi*sin(fCurTheta),radius1*sinPhi*sin(fCurTheta), radius1*cos(fCurTheta));
	for(int i =1; i <=iSegment; i++)
	{
		fCurTheta += fThetaStep;
		D3DXVECTOR3 Pt = D3DXVECTOR3(radius1*cosPhi*sin(fCurTheta),radius1*sinPhi*sin(fCurTheta), radius1*cos(fCurTheta));

		PT_VertColor vert1;
		vert1.pos = oldPt;
		vert1.color = fColor;
		ptsArray.Add(vert1);
		PT_VertColor vert2;
		vert2.pos = Pt;
		vert2.color = fColor;
		ptsArray.Add(vert2);

		oldPt = Pt;
	}


	fCurTheta = thetaMin;
	oldPt = D3DXVECTOR3(radius2*cosPhi*sin(fCurTheta),radius2*sinPhi*sin(fCurTheta), radius2*cos(fCurTheta));	
	for(int i =1; i <=iSegment; i++)
	{
		fCurTheta += fThetaStep;
		D3DXVECTOR3 Pt = D3DXVECTOR3(radius2*cosPhi*sin(fCurTheta),radius2*sinPhi*sin(fCurTheta), radius2*cos(fCurTheta));

		PT_VertColor vert1;
		vert1.pos = oldPt;
		vert1.color = fColor;
		ptsArray.Add(vert1);
		PT_VertColor vert2;
		vert2.pos = Pt;
		vert2.color = fColor;
		ptsArray.Add(vert2);

		oldPt = Pt;
	}

	fCurTheta = thetaMax;
	fCurPhi = phiMax;
	float cosTheta = cos(fCurTheta);
	float sinTheta = sin(fCurTheta);

	oldPt = D3DXVECTOR3(radius1*cos(fCurPhi)*sinTheta,radius1*sin(fCurPhi)*sinTheta, radius1*cosTheta);
	for(int i =iSegment; i >=1; i--)
	{
		fCurPhi -= fPhiStep;
		D3DXVECTOR3 Pt = D3DXVECTOR3(radius1*cos(fCurPhi)*sinTheta,radius1*sin(fCurPhi)*sinTheta, radius1*cosTheta);

		PT_VertColor vert1;
		vert1.pos = oldPt;
		vert1.color = fColor;
		ptsArray.Add(vert1);
		PT_VertColor vert2;
		vert2.pos = Pt;
		vert2.color = fColor;
		ptsArray.Add(vert2);

		oldPt = Pt;
	}

	fCurPhi = phiMax;
	oldPt = D3DXVECTOR3(radius2*cos(fCurPhi)*sinTheta,radius2*sin(fCurPhi)*sinTheta, radius2*cosTheta);	
	for(int i =iSegment; i >=1; i--)
	{
		fCurPhi -= fPhiStep;
		D3DXVECTOR3 Pt = D3DXVECTOR3(radius2*cos(fCurPhi)*sinTheta,radius2*sin(fCurPhi)*sinTheta, radius2*cosTheta);

		PT_VertColor vert1;
		vert1.pos = oldPt;
		vert1.color = fColor;
		ptsArray.Add(vert1);
		PT_VertColor vert2;
		vert2.pos = Pt;
		vert2.color = fColor;
		ptsArray.Add(vert2);

		oldPt = Pt;
	}

	fCurTheta = thetaMax;
	fCurPhi = phiMin;
	cosPhi = cos(fCurPhi);
	sinPhi = sin(fCurPhi);

	oldPt = D3DXVECTOR3(radius1*cosPhi*sin(fCurTheta),radius1*sinPhi*sin(fCurTheta), radius1*cos(fCurTheta));
	for(int i =iSegment; i >=1; i--)
	{
		fCurTheta -= fThetaStep;
		D3DXVECTOR3 Pt = D3DXVECTOR3(radius1*cosPhi*sin(fCurTheta),radius1*sinPhi*sin(fCurTheta), radius1*cos(fCurTheta));

		PT_VertColor vert1;
		vert1.pos = oldPt;
		vert1.color = fColor;
		ptsArray.Add(vert1);
		PT_VertColor vert2;
		vert2.pos = Pt;
		vert2.color = fColor;
		ptsArray.Add(vert2);

		oldPt = Pt;
	}

	fCurTheta = thetaMax;
	oldPt = D3DXVECTOR3(radius2*cosPhi*sin(fCurTheta),radius2*sinPhi*sin(fCurTheta), radius2*cos(fCurTheta));
	for(int i =iSegment; i >=1; i--)
	{
		fCurTheta -= fThetaStep;
		D3DXVECTOR3 Pt = D3DXVECTOR3(radius2*cosPhi*sin(fCurTheta),radius2*sinPhi*sin(fCurTheta), radius2*cos(fCurTheta));

		PT_VertColor vert1;
		vert1.pos = oldPt;
		vert1.color = fColor;
		ptsArray.Add(vert1);
		PT_VertColor vert2;
		vert2.pos = Pt;
		vert2.color = fColor;
		ptsArray.Add(vert2);

		oldPt = Pt;
	}

	fCurTheta = thetaMin;
	fCurPhi = phiMin;
	cosTheta = cos(fCurTheta);
	sinTheta = sin(fCurTheta);

	oldPt = D3DXVECTOR3(radius1*cos(fCurPhi)*sinTheta,radius1*sin(fCurPhi)*sinTheta, radius1*cosTheta);
	for(int i =1; i <=iSegment; i++)
	{
		fCurPhi += fPhiStep;
		D3DXVECTOR3 Pt = D3DXVECTOR3(radius1*cos(fCurPhi)*sinTheta,radius1*sin(fCurPhi)*sinTheta, radius1*cosTheta);

		PT_VertColor vert1;
		vert1.pos = oldPt;
		vert1.color = fColor;
		ptsArray.Add(vert1);
		PT_VertColor vert2;
		vert2.pos = Pt;
		vert2.color = fColor;
		ptsArray.Add(vert2);

		oldPt = Pt;
	}

	fCurPhi = phiMin;
	oldPt = D3DXVECTOR3(radius2*cos(fCurPhi)*sinTheta,radius2*sin(fCurPhi)*sinTheta, radius2*cosTheta);
	for(int i =1; i <=iSegment; i++)
	{
		fCurPhi += fPhiStep;
		D3DXVECTOR3 Pt = D3DXVECTOR3(radius2*cos(fCurPhi)*sinTheta,radius2*sin(fCurPhi)*sinTheta, radius2*cosTheta);

		PT_VertColor vert1;
		vert1.pos = oldPt;
		vert1.color = fColor;
		ptsArray.Add(vert1);
		PT_VertColor vert2;
		vert2.pos = Pt;
		vert2.color = fColor;
		ptsArray.Add(vert2);

		oldPt = Pt;
	}

	D3DXVECTOR3 Pt1 = D3DXVECTOR3(radius1*cos(phiMax)*sin(thetaMin),radius1*sin(phiMax)*sin(thetaMin), radius1*cos(thetaMin));
	D3DXVECTOR3 Pt2 = D3DXVECTOR3(radius2*cos(phiMax)*sin(thetaMin),radius2*sin(phiMax)*sin(thetaMin), radius2*cos(thetaMin));
	PT_VertColor vert1;
	vert1.pos = Pt1;
	vert1.color = fColor;
	ptsArray.Add(vert1);
	PT_VertColor vert2;
	vert2.pos = Pt2;
	vert2.color = fColor;
	ptsArray.Add(vert2);

	Pt1 = D3DXVECTOR3(radius1*cos(phiMax)*sin(thetaMax),radius1*sin(phiMax)*sin(thetaMax), radius1*cos(thetaMax));
	Pt2 = D3DXVECTOR3(radius2*cos(phiMax)*sin(thetaMax),radius2*sin(phiMax)*sin(thetaMax), radius2*cos(thetaMax));
	vert1.pos = Pt1;
	vert1.color = fColor;
	ptsArray.Add(vert1);
	vert2.pos = Pt2;
	vert2.color = fColor;
	ptsArray.Add(vert2);

	Pt1 = D3DXVECTOR3(radius1*cos(phiMin)*sin(thetaMax),radius1*sin(phiMin)*sin(thetaMax), radius1*cos(thetaMax));
	Pt2 = D3DXVECTOR3(radius2*cos(phiMin)*sin(thetaMax),radius2*sin(phiMin)*sin(thetaMax), radius2*cos(thetaMax));
	vert1.pos = Pt1;
	vert1.color = fColor;
	ptsArray.Add(vert1);
	vert2.pos = Pt2;
	vert2.color = fColor;
	ptsArray.Add(vert2);


	Pt1 = D3DXVECTOR3(radius1*cos(phiMin)*sin(thetaMin),radius1*sin(phiMin)*sin(thetaMin), radius1*cos(thetaMin));
	Pt2 = D3DXVECTOR3(radius2*cos(phiMin)*sin(thetaMin),radius2*sin(phiMin)*sin(thetaMin), radius2*cos(thetaMin));
	vert1.pos = Pt1;
	vert1.color = fColor;
	ptsArray.Add(vert1);
	vert2.pos = Pt2;
	vert2.color = fColor;
	ptsArray.Add(vert2);
}

void CRenderAssistLineShell::CreateAxisLine(float length, CGrowableArray<PT_VertColor>& ptsArray)
{
	PT_VertColor origin;
	origin.pos = D3DXVECTOR3(0,0,0);
	origin.color = D3DXVECTOR4(0,0,1,0);
	PT_VertColor AxisZ;
	AxisZ.pos = D3DXVECTOR3(0,0,length);
	AxisZ.color = D3DXVECTOR4(0,0,1,0);

	ptsArray.Add(origin);
	ptsArray.Add(AxisZ);

	origin.color = D3DXVECTOR4(0,1,0,0);
	PT_VertColor AxisY;
	AxisY.pos = D3DXVECTOR3(0,length,0);
	AxisY.color = D3DXVECTOR4(0,1,0,0);

	ptsArray.Add(origin);
	ptsArray.Add(AxisY);

	origin.color = D3DXVECTOR4(1,0,0,0);
	PT_VertColor AxisX;
	AxisX.pos = D3DXVECTOR3(length,0,0);
	AxisX.color = D3DXVECTOR4(1,0,0,0);

	ptsArray.Add(origin);
	ptsArray.Add(AxisX);
}

void CRenderAssistLineShell::CreateIntersectionLines(float radius, int iNewSegment, float thetaMin, float thetaMax, float phiMin, float phiMax, CGrowableArray<PT_VertColor>& ptsArray, D3DXVECTOR4 fColor)
{
	float fThetaStep = thetaMax / iNewSegment;
	float fPhiStep = phiMax / iNewSegment;

	PT_VertColor origin;
	origin.pos = D3DXVECTOR3(0,0,0);
	origin.color = fColor;

	float Length = radius;

	for (int j = 1; j <= iNewSegment; j++)
	{
		float fCurTheta = j*fThetaStep;
		for (int i = 0; i <= iNewSegment; i++)
		{
			float fCurPhi = i*fPhiStep;

			if( (j == 2 || j == 3) && (i == 2||i==3))
				Length = 7.0f;
			else
				Length = radius;

			if( (fCurTheta == D3DX_PI/2&&fCurPhi < 0.00001f) || (fCurTheta == D3DX_PI/2 && fCurPhi == D3DX_PI/2) )
				continue;

			PT_VertColor vert;
			vert.pos = D3DXVECTOR3(Length*cos(fCurPhi)*sin(fCurTheta), Length*sin(fCurPhi)*sin(fCurTheta), Length*cos(fCurTheta));
			vert.color = fColor;
			ptsArray.Add(origin);
			ptsArray.Add(vert);
		}
	}

}

void CRenderAssistLineShell::CreatePartialSphereLineSegs(float radius, int iSegment, float thetaMin, float thetaMax, float phiMin, float phiMax, CGrowableArray<PT_VertColor>& ptsArray, D3DXVECTOR4 fColor)
{
	float fThetaStep = thetaMax/iSegment;
	float fPhiStep = phiMax/iSegment;

	//x = rcos(phi)sin(theta)
	//y = rsin(phi)sin(theta)
	//z = rcos(theta)
	float fCurTheta = 0;
	float fCurPhi = 0;
	D3DXVECTOR3 oldPtXZ = D3DXVECTOR3(0,0,radius);
	for(int i = 1; i <= iSegment; i++)
	{
		fCurTheta += fThetaStep;
		//XZ plane
		D3DXVECTOR3 ptXZ = D3DXVECTOR3(radius*sin(fCurTheta), 0, radius*cos(fCurTheta));

		PT_VertColor vert1;
		vert1.pos = oldPtXZ;
		vert1.color = fColor;
		ptsArray.Add(vert1);
		PT_VertColor vert2;
		vert2.pos = ptXZ;
		vert2.color = fColor;
		ptsArray.Add(vert2);

		oldPtXZ = ptXZ;
	}

	//XY plane
	fCurTheta = D3DX_PI/2;
	fCurPhi = 0;
	D3DXVECTOR3 oldPtXY = D3DXVECTOR3(radius,0,0);
	for(int i = 1; i <= iSegment; i++)
	{
		fCurPhi += fPhiStep;
		D3DXVECTOR3 ptXY = D3DXVECTOR3(radius*cos(fCurPhi), radius*sin(fCurPhi), 0 );

		PT_VertColor vert1;
		vert1.pos = oldPtXY;
		vert1.color = fColor;
		ptsArray.Add(vert1);
		PT_VertColor vert2;
		vert2.pos = ptXY;
		vert2.color = fColor;
		ptsArray.Add(vert2);

		oldPtXY = ptXY;
	}

	//YZ plane
	fCurTheta = 0;
	fCurPhi = D3DX_PI/2;
	D3DXVECTOR3 oldPtYZ = D3DXVECTOR3(0,0,radius);

	for(int i = 1; i <= iSegment; i++)
	{
		fCurTheta += fThetaStep;
		D3DXVECTOR3 ptYZ = D3DXVECTOR3(0, radius*sin(fCurTheta), radius*cos(fCurTheta) );

		PT_VertColor vert1;
		vert1.pos = oldPtYZ;
		vert1.color = fColor;
		ptsArray.Add(vert1);
		PT_VertColor vert2;
		vert2.pos = ptYZ;
		vert2.color = fColor;
		ptsArray.Add(vert2);

		oldPtYZ = ptYZ;
	}

	float fLatitudeStep = 4;
	float fNewThetaStep = thetaMax/fLatitudeStep;
	fCurTheta = 0;
	for (int j = 1; j < fLatitudeStep; j++)
	{
		fCurTheta += fNewThetaStep;

		float sinTheta = sin(fCurTheta);
		float cosTheta = cos(fCurTheta);

		fCurPhi = 0;

		D3DXVECTOR3 oldPt = D3DXVECTOR3(radius*sinTheta,0,radius*cosTheta);
		for(int i = 1; (i <= iSegment&&fCurPhi<=phiMax); i++)
		{
			fCurPhi += fPhiStep;
			if( (radius == 10.0 || radius == 7.0 ) && ( fabs(fCurPhi - (D3DX_PI/2*0.5 + fPhiStep)) < 0.00001f)
				&& ( j==2||j==3 ))
			{
				oldPt = D3DXVECTOR3(radius*cos(D3DX_PI/2*0.75)*sinTheta, radius*sin(D3DX_PI/2*0.75)*sinTheta, radius*cosTheta);
				fCurPhi = D3DX_PI/2*0.75 + fPhiStep;
			}

			D3DXVECTOR3 pt = D3DXVECTOR3(radius*cos(fCurPhi)*sinTheta, radius*sin(fCurPhi)*sinTheta, radius*cosTheta);

			PT_VertColor vert1;
			vert1.pos = oldPt;
			vert1.color = fColor;
			ptsArray.Add(vert1);
			PT_VertColor vert2;
			vert2.pos = pt;
			vert2.color = fColor;
			ptsArray.Add(vert2);

			oldPt = pt;
		}
	}

	float fLongitudeStep = 4;
	float fNewPhiStep = phiMax / fLongitudeStep;
	fCurPhi = 0;
	for (int j = 1; j < fLongitudeStep; j++)
	{
		fCurPhi += fNewPhiStep;

		float sinPhi = sin(fCurPhi);
		float cosPhi = cos(fCurPhi);

		fCurTheta = 0;

		D3DXVECTOR3 oldPt = D3DXVECTOR3(0,0,radius);
		for(int i = 1; (i <= iSegment&&fCurTheta<=thetaMax); i++)
		{
			fCurTheta += fThetaStep;

			if( (radius == 10.0 || radius == 7.0 ) && ( fabs(fCurTheta - (D3DX_PI/2*0.5 + fThetaStep)) < 0.00001f)
				&& ( j==2||j==3 ))
			{
				oldPt = D3DXVECTOR3(radius*cosPhi*sin(D3DX_PI/2*0.75), radius*sinPhi*sin(D3DX_PI/2*0.75), radius*cos(D3DX_PI/2*0.75));
				fCurTheta = D3DX_PI/2*0.75 + fThetaStep;
			}

			D3DXVECTOR3 pt = D3DXVECTOR3(radius*cosPhi*sin(fCurTheta), radius*sinPhi*sin(fCurTheta), radius*cos(fCurTheta));

			PT_VertColor vert1;
			vert1.pos = oldPt;
			vert1.color = fColor;
			ptsArray.Add(vert1);
			PT_VertColor vert2;
			vert2.pos = pt;
			vert2.color = fColor;
			ptsArray.Add(vert2);

			oldPt = pt;
		}
	}

}

void CRenderAssistLineShell::InitEffectsVariables()
{
	if(!m_pEffect) 
		{
#ifdef _DEBUG
			OUTPUTERRORINFO;
#endif
			return;
		}	
	m_pRenderTech = m_pEffect->GetTechniqueByName("RenderAssistLine");
	m_pWorldViewProjMat = m_pEffect->GetVariableByName("mWorldViewProjection")->AsMatrix();
}

void CRenderAssistLineShell::ReloadEffectsDebug(ID3D11Device* pd3dDevice, CDirectoryUtil* pDirUtil)
{
	SAFE_RELEASE(m_pEffect);
	//create effects
	TCHAR ShaderFileDir[MAX_PATH];
	enum SUBDIRECTORY subfolder = SUBDIRECTORY::SHADERSDIR;
	pDirUtil->GetAbsoluteFileFolder(L"RenderAssistLine.fx",subfolder, ShaderFileDir);
	HRESULT hr = CD3DUtilityFunction::CreateEffectsFromFile(pd3dDevice, ShaderFileDir, NULL, "fx_5_0", &m_pEffect);
	InitEffectsVariables();
}

HRESULT CRenderAssistLineShell::OnD3D11CreateDevice(ID3D11Device* pd3dDevice, const DXGI_SURFACE_DESC* pBackBufferSurfaceDesc, CDirectoryUtil* pDirUtil, void* pUserContext)
{
	HRESULT hr = S_OK;

	//CREATE RENDER ASSIST LINE
	CGrowableArray<PT_VertColor> Points;
	CreateAxisLine(14.0f,Points);
	int iSegNum = 200;
	CreateIntersectionLines(10.0f,4,0,D3DX_PI/2,0,D3DX_PI/2,Points,D3DXVECTOR4(0.3,0.3,0.3,0));
	CreatePartialSphereLineSegs(10.0f,iSegNum,0,D3DX_PI/2,0,D3DX_PI/2,Points,D3DXVECTOR4(1,1,0,0));
	CreatePartialSphereLineSegs(7.0f,iSegNum,0,D3DX_PI/2,0,D3DX_PI/2,Points,D3DXVECTOR4(0,1,1,0));
	CreatePartialSphereLineSegs(5.0f,iSegNum,0,D3DX_PI/2,0,D3DX_PI/2,Points,D3DXVECTOR4(1,0,0,0));
	CreatePartialSphereLineSegs(3.5f,iSegNum,0,D3DX_PI/2,0,D3DX_PI/2,Points,D3DXVECTOR4(0,1,0,0));
	CreatePartialSphereLineSegs(2.0f,iSegNum,0,D3DX_PI/2,0,D3DX_PI/2,Points,D3DXVECTOR4(0,0,1,0));

	CreateEmphasizeLine(iSegNum/4, D3DX_PI/2*(0.5), D3DX_PI/2*(0.75), D3DX_PI/2*(0.5), D3DX_PI/2*(0.75), 7.0, 10.0,Points,D3DXVECTOR4(0,0,0,0));
	m_iNumAssistVertices = Points.GetSize();
	//buffer
	D3D11_BUFFER_DESC BufferDesc;
	BufferDesc.ByteWidth = Points.GetSize() * sizeof(PT_VertColor);
	BufferDesc.Usage = D3D11_USAGE_IMMUTABLE;
	BufferDesc.BindFlags = D3D10_BIND_VERTEX_BUFFER;
	BufferDesc.CPUAccessFlags = 0;
	BufferDesc.MiscFlags = 0;

	D3D11_SUBRESOURCE_DATA InitData;
	InitData.pSysMem = Points.GetData();
	SAFE_RELEASE(m_pAssistLineVB);
	V_RETURN( pd3dDevice->CreateBuffer( &BufferDesc, &InitData, &m_pAssistLineVB ) );

	//create effects
	TCHAR ShaderFileDir[MAX_PATH];
	enum SUBDIRECTORY subfolder = SUBDIRECTORY::SHADERSDIR;
	pDirUtil->GetAbsoluteFileFolder(L"RenderAssistLine.fx",subfolder, ShaderFileDir);
	hr = CD3DUtilityFunction::CreateEffectsFromFile(pd3dDevice, ShaderFileDir, NULL, "fx_5_0", &m_pEffect);
	InitEffectsVariables();
	//create vertex layout
	const D3D11_INPUT_ELEMENT_DESC layout[2] =
	{
		{ "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0,  0, D3D11_INPUT_PER_VERTEX_DATA, 0 },
		{ "COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0 },
	};
	//vb layout
	SAFE_RELEASE(m_pAssistLineVBLayout);
	V(CD3DUtilityFunction::CreateVertexLayout(pd3dDevice,layout,ARRAYSIZE(layout), m_pRenderTech, &m_pAssistLineVBLayout));

	return hr;
}

HRESULT CRenderAssistLineShell::OnD3D11ResizedSwapChain( ID3D11Device* pd3dDevice, IDXGISwapChain* pSwapChain, const DXGI_SURFACE_DESC* pBackBufferSurfaceDesc, 
														CDirectoryUtil* pDirUtil, void* pUserContext )
{
	return S_OK;
}

void CRenderAssistLineShell::OnD3D11ReleasingSwapChain( void* pUserContext )
{
	return;
}

void CRenderAssistLineShell::OnD3D11DestroyDevice( void* pUserContext )
{
	SAFE_RELEASE(m_pAssistLineVB);
	SAFE_RELEASE(m_pAssistLineVBLayout);
	RenderTech::OnD3D11DestroyDevice(pUserContext);
}

void CRenderAssistLineShell::OnD3D11FrameRender( ID3D11Device* pd3dDevice, ID3D11DeviceContext* pd3dImmediateContext, CBaseCamera* pViewCamera, 
	                                               CDirectoryUtil* pDirUtil, double fTime, float fElapsedTime, void* pUserContext )
{
	CModelViewerCamera* pCamera = static_cast<CModelViewerCamera*>(pViewCamera);
	D3DXMATRIX mWorld = *(pCamera->GetWorldMatrix());
	D3DXMATRIX mView = *(pCamera->GetViewMatrix());
	D3DXMATRIX mProj = *(pCamera->GetProjMatrix());
	D3DXMATRIX mWorldViewProjection = mWorld * mView * mProj;


	// Set render resources
	pd3dImmediateContext->IASetInputLayout( m_pAssistLineVBLayout );
	ID3D11Buffer* pVB[1] = { m_pAssistLineVB };
	UINT pStride[1] = { sizeof(PT_VertColor) };
	UINT pOffset[1] = { 0 };
	pd3dImmediateContext->IASetVertexBuffers( 0, 1, pVB, pStride, pOffset );
	pd3dImmediateContext->IASetPrimitiveTopology( D3D11_PRIMITIVE_TOPOLOGY_LINELIST);

	// Render objects here...
	// Apply the technique contained in the effect 
	D3DX11_TECHNIQUE_DESC Desc;
	m_pRenderTech->GetDesc( &Desc );
	m_pWorldViewProjMat->SetMatrix((float*)(&mWorldViewProjection));

	for( UINT iPass = 0; iPass < Desc.Passes; iPass++ )
	{
		m_pRenderTech->GetPassByIndex( iPass )->Apply( 0, pd3dImmediateContext );
		pd3dImmediateContext->Draw(m_iNumAssistVertices,0);		
	}

}